<?php

/**
 * 黑名单管理
 * File Name：BlacklistController.php
 * File Encoding：UTF-8
 * File New Time：2014-5-23 9:31:10
 * Author：水平凡
 * Mailbox：admin@abc3210.com
 */
class BlacklistController extends AdminBase {

    //黑名单列表
    public function actionIndex() {
        //搜索
        if (IS_POST) {
            $this->redirect(self::U('index', $_POST));
            exit;
        }
        //分页
        $pageId = isset($_GET['page']) ? (int) $_GET['page'] : 1;
        //分页数
        $limit = 20;
        //报名模型
        $model = BlacklistModel::model();
        //条件数组
        $where = array(
            'order' => 'id desc',
        );
        $keyword = trim($_GET['keyword']);
        if ($keyword) {
            $where['nick'] = array('LIKE', "%{$keyword}%");
            $this->assign('keyword', $keyword);
        }
        $criteria = $model->where($where);
        //信息总数
        $count = $model->count($criteria);
        //分页
        $page = self::page($count, $limit, $pageId);
        //查询信息
        $criteria->limit = $page->listRows;
        $criteria->offset = $page->firstRow;
        $data = $model->findAll($criteria);

        $this->assign("Page", $page->show());
        $this->assign('data', $data);
        $this->assign('count', $count);
        $this->render();
    }

    //添加黑名单
    public function actionAdd() {
        if (IS_POST) {
            if (BlacklistModel::model()->addBlack($_POST)) {
                $this->success('添加黑名单成功！', self::U('index'));
            } else {
                $error = BlacklistModel::model()->getOneError();
                $this->error($error ? $error : '添加黑名单失败！');
            }
        } else {
            $this->render();
        }
    }

    //修改黑名单
    public function actionEdit() {
        if (IS_POST) {
            if (BlacklistModel::model()->editorBlack($_POST)) {
                $this->success('修改成功！', self::U('index'));
            } else {
                $error = BlacklistModel::model()->getOneError();
                $this->error($error ? $error : '修改失败！');
            }
        } else {
            $id = Yii::app()->request->getParam('id');
            //查询报名信息
            $data = BlacklistModel::model()->findByPk($id);
            if (empty($data)) {
                $this->error('该信息不存在！');
            }
            $this->assign('data', $data);
            $this->render();
        }
    }

    //删除黑名单
    public function actionDelete() {
        $this->baseDelete('BlacklistModel', 'index');
    }

}
